<template>
  <!-- 专利 -->
  <el-descriptions :column="2" size="large">
    <el-descriptions-item label-class-name="right-align" label='成果来源'>
      <span class="text--info subtext" v-if='softwareInfo.projectId'>项目</span>
      <span class="text--info subtext" v-else>非项目</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='软件名称'>
      <span class="text--info subtext">{{softwareInfo.softwareName}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='所属项目' v-if='softwareInfo?.projectId'>
      <span class="text--info subtext">{{projectInfo?.projectName}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='项目编号' v-if='softwareInfo?.projectId'>
      <span class="text--info subtext">{{projectInfo.projectCode}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='登记号'>
      <span class="text--info subtext">{{softwareInfo?.signNum}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='开发完成日期'>
      <span class="text--info subtext">{{softwareInfo?.devFinishTime}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='权利取得方式'>
      <span class="text--info subtext">{{model.copyrightAcquisitions[softwareInfo?.copyrightAcquisition]}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='权利范围'>
      <span class="text--info subtext">{{model.copyrightScopes[softwareInfo?.copyrightScope]}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='所属公司主体'>
      <span class="text--info subtext">{{softwareInfo.companyEntityName}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='首次发表日期'>
      <span class="text--info subtext">{{softwareInfo.firstPublishTime}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='完成人'>
      <span class="text--info subtext" v-for="item in softwareInfo.copyrightOwnerList" :key="item.id">{{item.bizName}}&nbsp;&nbsp;</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='著作权人'>
      <span class="text--info subtext" v-for="item in softwareInfo.authorList" :key="item.id">{{item.bizName}}&nbsp;&nbsp;</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='上传文档'>
      <div v-if="softwareInfo.attachmentList?.length" class="file-wrap">
        <p
          class="text--info download-link subtext"
          v-for="(obj, index) in softwareInfo?.attachmentList"
          :key="index"
          @click.prevent="handlePreview(obj)"
        >
          <el-link :underline="false" icon="el-icon-folder">{{ obj?.fileName }}&nbsp;&nbsp;</el-link>
        </p>
      </div>
      <div class="text--info subtext file-wrap" v-else> - </div>
    </el-descriptions-item>
  </el-descriptions>
</template>

<script lang="ts" setup>
import {ref, watch,reactive} from "vue";
import { getSoftwareById } from "/@/api/document";
const props = defineProps({
  projectInfo: {
    type: Object,
    default:()=>{}
  },
});
let info = ref({});
let softwareInfo = ref({})
let model = reactive({
  copyrightScopes: {1: "全部权利" },
  copyrightAcquisitions: {
    1: "原始取得",
    2: "继受取得"
  },
  patentTypes: {
    1: "发明专利" ,
    2: "实用新型专利",
    3: "外观设计专利"
  }
})

const getData = async id => {
  const { data,code } = await getSoftwareById(id);
  if(code == 200){
    softwareInfo.value = data;
    softwareInfo.value.copyrightOwnerList = JSON.parse(data.copyrightOwner);
    softwareInfo.value.authorList = JSON.parse(data.author);
    softwareInfo.value.attachmentList = JSON.parse(data.attachment);
  }
};

const handlePreview = (item: any) => {
  if (item.response) {
    window.open(
      `${location.origin}${location.pathname}#/online?uuidFile=${item?.response.data.uuidFile}&fileName=${item?.response.data.fileName}`
    );
  } else {
    window.open(
      `${location.origin}${location.pathname}#/online?uuidFile=${item.uuidFile}&fileName=${item.fileName}`
    );
  }
};

watch(
  () => props.projectInfo,
  newvalue => {
    info.value = newvalue;
    const kyId = newvalue.kyId
    if(kyId){
      getData(kyId)
    }
  },
  { immediate: true }
);
</script>

<style lang="scss" scoped>
  .file-wrap{
    display: inline-block;
    vertical-align: top
  }
</style>
